﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using SXFramWork.Core;
using SXFramWork.Model;
using SXFramWork.Service;

namespace SXFramWork.API.Controllers.Admin
{
    /// <summary>
    /// 消息管理
    /// </summary>
    public class SysMessageController : WebController
    {
        private readonly ISysMessageService _service;
        public SysMessageController(ISysMessageService sysMessageService)
        {
            _service = sysMessageService;
        }
        /// <summary>
        /// 查询列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        [Menu("消息通知")]
        public async Task<IApiResult> List([FromQuery]SysMessageQueryModel model )
        {
            return await _service.Query(model);
        }
        /// <summary>
        /// 添加消息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Power("添加消息")]
        public async Task<IApiResult> Add([FromBody] MessageAddModel model)
        {
            return await _service.Add(model);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Power("删除")]
        [Log]
        public async Task<IApiResult> Delete([FromBody]List<string> ids)
        {
            return await _service.Delete(ids);
        }

        /// <summary>
        /// 读消息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Power("消息阅读")]
        public async Task<IApiResult> ReadMsg([FromBody]string id)
        {
            return await _service.ReadMsg(id);
        }
        /// <summary>
        /// 查询未读消息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Power("查询未读信息")]
        public async Task<IApiResult> GetUnReadListJson()
        {
            var list= await _service.GetUnReadList();
            return ApiResult.Ok(list);
        }

        /// <summary>
        /// 全部消息已读
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Power("全部已读")]
        public async Task<IApiResult> ReadAllMsg([FromBody]int type)
        {
            return await _service.ReadAllMsg(type);
        }


    }
}